package com.ruitu.health_1.ui;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ruitu.arad.base.BaseActivity;
import com.ruitu.arad.support.widget.dialog.CustomAlertDialog;
import com.ruitu.arad.util.ToastUtils;
import com.ruitu.health_1.R;
import com.ruitu.health_1.dao.bean.Pay;
import com.ruitu.health_1.mvp.model.OrderModel;
import com.ruitu.health_1.mvp.presenter.OrderPresenter;
import com.ruitu.router_module.bean.user.Address;
import com.ruitu.router_module.util.ReqUtil;

import java.util.HashMap;
import java.util.Map;

public class PayOrderActivity extends BaseActivity<OrderPresenter.PayOrderP, OrderModel.PayOrderM> {
    private TextView tv_name;
    private TextView tv_tel;
    private TextView tv_detailed_address;
    private TextView tv_need_pay;
    private RelativeLayout rl_yue_pay;

    private Address address;
    private Pay pay;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_pay_order;
    }

    @Override
    protected void initViews() {
        super.initViews();
        setHeadTitle("支付订单");
        address = (Address) getIntent().getExtras().get("address");
        pay = (Pay) getIntent().getExtras().get("pay");
        tv_name = findViewById(R.id.tv_name);
        tv_tel = findViewById(R.id.tv_tel);
        tv_detailed_address = findViewById(R.id.tv_detailed_address);
        tv_need_pay = findViewById(R.id.tv_need_pay);
        rl_yue_pay = findViewById(R.id.rl_yue_pay);
        setAddress(address);
        String price = TextUtils.isEmpty(pay.getPayAmount()) ? pay.getPrice() : pay.getPayAmount();
        tv_need_pay.setText("￥" + price);
        setOnClickListener(rl_yue_pay);
    }

    private void setAddress(Address address) {
        tv_name.setText(address.getName());
        tv_tel.setText(address.getPhoneNumber());
        tv_detailed_address.setText(address.getProvince() + address.getCity() + address.getRegion() + address.getDetailAddress());
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        if (rl_yue_pay == v) {
            Map<String, String> map = new HashMap<>();
            map.put("orderId", pay.getOrderId());
            map.put("status", "2");
            showProgress();
            p.balancePay(ReqUtil.getBody(map, true));
        }
    }

    public void paySuc() {
        ToastUtils.showShort("支付成功");
//        startActivity(PaySucceedActivity.class);
        finish();
    }

    @Override
    public void onBackPressed() {
        CustomAlertDialog dialog = new CustomAlertDialog(this, "是否已支付", new CustomAlertDialog.OkOnClickListener() {
            @Override
            public void OkOnClick() {
                finish();
            }
        });
        dialog.show();
    }
}
